package com.zhukaiyuan.oauth2.sys.controller;

import com.zhukaiyuan.oauth2.cms.entity.Content;
import com.zhukaiyuan.oauth2.cms.service.ContentService;
import com.zhukaiyuan.oauth2.sys.service.LoginService;
import com.zhukaiyuan.oauth2.utils.Header;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.Map;

@RequestMapping("/sys/login")
@RestController
public class LoginController {

    @Autowired
    private LoginService loginService;

    @Resource
    public HttpServletRequest request;

    @PostMapping
    public Map<String, String> login(String username, String passwd){
        Map<String, String> res = loginService.getToken(username, passwd);
        return res;
    }

    /**
     * 刷新令牌
     * @return {@link }
     */
    @PostMapping("refresh")
    public Map<String, String> refresh() {
        String token = Header.getAuthorization(request.getHeader("Authorization"));
        return loginService.refresh(token);
    }

}
